
const db = require('./datastore.js')
const mysql = require('./data/mysql.js')
// const redis = require('redis')

/**
 * 数据操作工具
 */
module.exports = {

    // redisClient : redis.createClient(RDS_PORT, RDS_HOST, RDS_OPTS),

    type : db.read().get('coonType').value(),

    select : function(table,where){

    },

    insert : function(table,obj){
        let sql = "";
        switch(this.type){
            case "mysql" : 
                let result = this.convertData(obj);
                sql = "insert into "+ table +" ("+ result.key +") values ("+ result.value +")";
                console.log("sql:",sql);
                break;
        }
    },

    update : function(table,obj){

    },

    delete : function(table,obj){

    },

    execUpdate : function(sql){
        
    },
    convertData(obj){
        let key = [],value=[];
        for(let k in obj){
            key.push(k);value.push(obj[k]);
        }
        return {
            key : key,
            value : value
        }
    }
};